package com.avic.rong.adapter;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Creater: Created by wangyz on 2018/12/26.
 * Email: 936804097@qq.com
 */
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {

    private final int normal;
    private final int margin;
    //  1   猜你需要
    private int type;


    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        if (type==1){
            //不是第一个的格子都设一个左边和底部的间距
            outRect.left = margin;
            outRect.bottom = margin;
            //由于每行都只有2个，所以第一个都是2的倍数，把左边距设为0
            if (parent.getChildLayoutPosition(view) %2==0) {
                outRect.left = 0;
                outRect.bottom = margin;
            }
        }else {
            outRect.top = normal;
            outRect.bottom = normal;
            if (parent.getChildAdapterPosition(view) % 3 == 0) {
                outRect.right = normal;
                outRect.left = normal;
            } else if (parent.getChildAdapterPosition(view) % 3 == 1) {
                outRect.right = margin;
                outRect.left = margin;
            } else if (parent.getChildAdapterPosition(view) % 3 == 2) {
                outRect.right = normal;
                outRect.left = normal;
            }
        }


    }

    public SpaceItemDecoration(int normal, int margin,int type) {
        this.normal = normal;
        this.margin = margin;
        this.type=type;

    }
    public SpaceItemDecoration(int normal, int margin) {
        this.normal = normal;
        this.margin = margin;
    }

}
